package com.jingfu.configuration.flyway;

import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * flyway数据库版本控制配置
 * @author jingfuu@163.com
 * @version v1.0
 * @date 2022/1/6 下午2:28
 **/
@Component
public class FlywayDataMigration {
    @Autowired
    DataSource dataSource;

    @PostConstruct
    public void migrate() {
        //使用默认配置初始化Flyway，sql脚本位置，默认位于：classpath：db/migration
        Flyway flyway = Flyway
                .configure()
                .dataSource(dataSource)
                .load();
        flyway.migrate();
    }

}
